package com.prodog.gamemodule.fight.handler;

import com.prodog.command.annonations.*;
import com.prodog.command.entity.CommandResult;
import com.prodog.command.entity.RoleGameCommand;
import com.prodog.gamemodule.fight.service.FightService;
import com.prodog.gamemodule.interceptor.NoMonsterInterceptor;
import com.prodog.usermodule.role.interceptor.StateInterceptor;
import com.prodog.usermodule.user.interceptor.NotRegistInterceptor;
import lombok.RequiredArgsConstructor;

@CommandBean(setName = "战斗操作")
@RequiredArgsConstructor
@Interceptors(iptors = {
        @Iptor(value = NotRegistInterceptor.class),
})
public class FightHandler {
    private final FightService fightService;

    @Command("战斗")
    @Interceptors(iptors = {
            @Iptor(value = NoMonsterInterceptor.class, msg = "该地点未发现怪物。"),
            @Iptor(value = StateInterceptor.class, params = "{'requiredStates':[1]}", msg = "[{{state}}]状态下无法进行此操作。")

    })
    public CommandResult fight(RoleGameCommand command) {
        try {
            return fightService.fight(command);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器发生错误，进入战斗失败");
        }
    }

    @Command(value = "攻击\\s*(\\d*)", props = "index")
    @Interceptors(iptors = {
            @Iptor(value = NoMonsterInterceptor.class, msg = "该地点未发现怪物。")
    })
    public CommandResult fight(RoleGameCommand command, Integer index) {
        try {
            return fightService.attack(command, index);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器发生错误，攻击失败");
        }
    }
}
